package com.seeyon.ctp.rest.resources;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.seeyon.apps.kk.manager.FreemarkFlowManager;
import com.seeyon.apps.kk.manager.restImpl.MeasuringEquipmentImpl;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.kk.utils.ValueUtils;

/**
 * 对NC提供rest接口 修改测量设备信息底表数据
 * 
 * @author seeyon
 *
 */
@Path("/kk/equip")
public class MeasuringEquipment extends BaseResource {
	private static final Log log = LogFactory.getLog(MeasuringEquipment.class);
	String msg = "";
	String code = "0003";
	
	
	private MeasuringEquipmentImpl measuringEquipmentImpl = (MeasuringEquipmentImpl) AppContext.getBean("measuringEquipmentImpl");

	
	/**
	 * 修改记录
	 * @param params  {assetNo:"",isQualified:"",type:""}   type 已送检1、已检验2、 已领取3
	 * @return
	 */
	@POST
	@Path("/updCheckoutRecord")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	public Response updCheckoutRecord(List<Map<String, Object>> params) {
		log.info("远程调用："+params+"\n调用日期："+DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		Map<String, Object> rsMap = new HashMap<String, Object>();
		for (Map<String, Object> map : params) {
			if (MapUtils.isNotEmpty(map)) {
				measuringEquipmentImpl.updCheckoutRecord(map);
				code = "0001";
				msg = "";
			}else{
				code = "0002";
				msg = "params=" + params;
			}
		}
		// 返回信息
		rsMap.put("code", code);
		rsMap.put("massage", msg);
		return ok(rsMap);
	}
	
	
	/**
	 * 合同付款金额 从NC回写
	 * @param params
	 * @return
	 */
	@POST
	@Path("/writeBackAmount")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_HTML })
	public Response writeBackAmount(Map<String, Object> params) {
		log.info("远程调用："+params+"\n调用日期："+DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
		Map<String, Object> rsMap = measuringEquipmentImpl.writeBackAmount(params);
		return ok(rsMap);
	}


}
